class Solution
{
public:
    int numberOfBoomerangs(vector<vector<int>> &points)
    {
        int n = points.size();
        vector<unordered_map<int, int>> distCounts(n);
        auto distAt = [&](int i, int j)
        {
            int dx = points[i][0] - points[j][0];
            int dy = points[i][1] - points[j][1];
            return dx * dx + dy * dy;
        };
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                int dist = distAt(i, j);
                ++distCounts[i][dist];
            }
        }
        int result = 0;
        for (auto &distCount : distCounts)
        {
            for (auto &[dist, count] : distCount)
            {
                result += count * (count - 1);
            }
        }
        return result;
    }
};